package com.augurit.common.calendar.convert;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.augurit.common.calendar.web.form.SysCalEventTypeForm;
import com.augurit.common.entity.SysCalEventType;
import com.augurit.common.util.lang.DateUtils;

public class SysCalEventTypeConvertor {
	public static SysCalEventTypeForm convertVoToForm(SysCalEventType entity) {
		if(entity != null) {
			SysCalEventTypeForm form = new SysCalEventTypeForm();
			form.setTypeId(entity.getTypeId());
			form.setTypeName(entity.getTypeName());
			form.setColor(entity.getColor());
			return form;
		}else
			return null;
	}
	
	public static void convertFormToVo(SysCalEventTypeForm form, SysCalEventType entity) {
		if(entity != null && form != null) {
			entity.setTypeId(form.getTypeId());
			if(form.getTypeName() != null && form.getTypeName().trim().length() > 0)
				entity.setTypeName(form.getTypeName().trim());
			entity.setColor(form.getColor());
		}
	}
	
	public static List<SysCalEventTypeForm> convertVoListToFormList(List<SysCalEventType> sysCalEventTypeList) {
		if(sysCalEventTypeList != null && sysCalEventTypeList.size() > 0) {
			List<SysCalEventTypeForm> sysCalEventTypeFormList = new ArrayList();
			for(int i=0; i<sysCalEventTypeList.size(); i++) {
				sysCalEventTypeFormList.add(convertVoToForm(sysCalEventTypeList.get(i)));
			}
			return sysCalEventTypeFormList;
		}
		return null;
	}
	
	public static List<Map> convertVoListToMapList(List<SysCalEventType> sysCalEventTypeList) {
		if(sysCalEventTypeList != null && sysCalEventTypeList.size() > 0) {
			List<Map> mapList = new ArrayList();
			for(int i=0; i<sysCalEventTypeList.size(); i++) {
				SysCalEventType entity = sysCalEventTypeList.get(i);
				Map<String, String> map = new HashMap();

				map.put("typeId", entity.getTypeId() == null ? "" : entity.getTypeId().toString());
				map.put("typeName", entity.getTypeName());
				map.put("color", entity.getColor() == null ? "" : entity.getColor().toString());
				
				mapList.add(map);
			}
			return mapList;
		}
		return null;
	}
	
	public static List<SysCalEventType> convertFormListToVoList(List<SysCalEventTypeForm> sysCalEventTypeFormList) {
		if(sysCalEventTypeFormList != null && sysCalEventTypeFormList.size() > 0) {
			List<SysCalEventType> sysCalEventTypeList = new ArrayList();
			for(int i=0; i<sysCalEventTypeFormList.size(); i++) {
				SysCalEventType sysCalEventType = new SysCalEventType();
				convertFormToVo(sysCalEventTypeFormList.get(i), sysCalEventType);
				sysCalEventTypeList.add(sysCalEventType);
			}
			return sysCalEventTypeList;
		}
		return null;
	}
}